package com.szgz.platform.model;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * 任务步骤模板实体类
 * 对应task_step_templates表
 */
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("task_step_templates")
public class TaskStepTemplate {

    /**
     * 模板唯一标识符
     */
    @TableId(value = "id", type = IdType.AUTO)
    private Long id;

    /**
     * 模板名称
     */
    @TableField("template_name")
    private String templateName;

    /**
     * 模板类型：basic(基础), coding(编程), quiz(测验), project(项目)
     */
    @TableField("template_type")
    private String templateType;

    /**
     * 步骤类型
     */
    @TableField("step_type")
    private String stepType;

    /**
     * 标题模板，支持变量占位符
     */
    @TableField("title_template")
    private String titleTemplate;

    /**
     * 描述模板
     */
    @TableField("description_template")
    private String descriptionTemplate;

    /**
     * 内容模板
     */
    @TableField("content_template")
    private String contentTemplate;

    /**
     * 要求模板
     */
    @TableField("requirements_template")
    private String requirementsTemplate;

    /**
     * 默认预计时间
     */
    @TableField("estimated_time")
    private Integer estimatedTime;

    /**
     * 默认最大分值
     */
    @TableField("max_score")
    private BigDecimal maxScore;

    /**
     * 默认及格分值
     */
    @TableField("pass_score")
    private BigDecimal passScore;

    /**
     * 默认是否必做
     */
    @TableField("is_required")
    private Boolean isRequired;

    /**
     * 默认是否可跳过
     */
    @TableField("can_skip")
    private Boolean canSkip;

    /**
     * 模板变量定义，JSON格式
     */
    @TableField("variables")
    private String variables;

    /**
     * 使用次数
     */
    @TableField("usage_count")
    private Integer usageCount;

    /**
     * 是否公开：1-公开，0-私有
     */
    @TableField("is_public")
    private Boolean isPublic;

    /**
     * 状态：active(激活), inactive(停用)
     */
    @TableField("status")
    private String status;

    /**
     * 创建时间
     */
    @TableField(value = "created_at", fill = FieldFill.INSERT)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime createdAt;

    /**
     * 更新时间
     */
    @TableField(value = "updated_at", fill = FieldFill.INSERT_UPDATE)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime updatedAt;

    /**
     * 创建者ID
     */
    @TableField("created_by")
    private Long createdBy;

    /**
     * 模板类型枚举
     */
    public enum TemplateType {
        BASIC("basic", "基础"),
        CODING("coding", "编程"),
        QUIZ("quiz", "测验"),
        PROJECT("project", "项目");

        private final String code;
        private final String label;

        TemplateType(String code, String label) {
            this.code = code;
            this.label = label;
        }

        public String getCode() {
            return code;
        }

        public String getLabel() {
            return label;
        }

        public static TemplateType fromCode(String code) {
            for (TemplateType type : values()) {
                if (type.code.equals(code)) {
                    return type;
                }
            }
            return BASIC;
        }
    }

    /**
     * 模板状态枚举
     */
    public enum TemplateStatus {
        ACTIVE("active", "激活"),
        INACTIVE("inactive", "停用");

        private final String code;
        private final String label;

        TemplateStatus(String code, String label) {
            this.code = code;
            this.label = label;
        }

        public String getCode() {
            return code;
        }

        public String getLabel() {
            return label;
        }

        public static TemplateStatus fromCode(String code) {
            for (TemplateStatus status : values()) {
                if (status.code.equals(code)) {
                    return status;
                }
            }
            return ACTIVE;
        }
    }
} 